package com.lesso.zgs.sunflower.infra.repository.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.domain.repository.EmployeeDeviceRepository;
import com.lesso.zgs.sunflower.infra.mapper.EmployeeDeviceMapper;
import com.lesso.zgs.sunflower.model.EmployeeDevice;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeDeviceQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.EmployeeDeviceVO;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * EmployeeDeviceRepositoryImpl
 *
 * @author zgs
 * @since 2025-07-03
 */
@Repository
public class EmployeeDeviceRepositoryImpl implements EmployeeDeviceRepository {
    private final EmployeeDeviceMapper employeeDeviceMapper;

    public EmployeeDeviceRepositoryImpl(EmployeeDeviceMapper employeeDeviceMapper) {
        this.employeeDeviceMapper = employeeDeviceMapper;
    }

    @Override
    public Integer save(EmployeeDevice employeeDevice) {
        employeeDeviceMapper.insert(employeeDevice);
        return Math.toIntExact(employeeDevice.getId());
    }

    @Override
    public Integer delete(Long id) {
        return employeeDeviceMapper.deleteById(id);
    }

    @Override
    public Page<EmployeeDeviceVO> getPageList(EmployeeDeviceQueryDTO dto) {
        if (dto == null) {
            throw new IllegalArgumentException("EmployeeDeviceQueryDTO is null");
        }
        Page<EmployeeDeviceVO> page = new Page<>(dto.getCurrent(), dto.getSize());
        List<EmployeeDeviceVO> list = employeeDeviceMapper.selectPageList(page, dto);
        return page.setRecords(list);
    }

    @Override
    public List<EmployeeDeviceVO> getByEmployeeId(Long employeeId) {
        return employeeDeviceMapper.selectByEmployeeId(employeeId);
    }
} 